﻿namespace Traductor{
using TUVienna.CS_CUP.Runtime;
using System;
%%
%cup
%ignorecase

DIG=[0-9]
LETRAS=[a-zA-Z]
ID=([a-z]|[A-Z])([a-z]|[A-Z]|[0-9])*
WHITE_SPACE_CHAR=[\n\ \t\b\012]
STRING_TEXT=(\\\"|[^\n\"]|\\{WHITE_SPACE_CHAR}+\\)*

%%
"int"		{ return new Symbol(sym.tk_int); }
"["			{ return new Symbol(sym.abrecorchete); }
"]"			{ return new Symbol(sym.cierracorchete); }
"="			{ return new Symbol(sym.igual); }
"string"	{ return new Symbol(sym.tk_string); }
"if"		{ return new Symbol(sym.tk_if); }
"("			{ return new Symbol(sym.abreparentesis); }
")"			{ return new Symbol(sym.cierraparentesis); }
"{"			{ return new Symbol(sym.abrellave); }
"}"			{ return new Symbol(sym.cierrallave); }		
"else"		{ return new Symbol(sym.tk_else); }
"switch"	{ return new Symbol(sym.tk_switch); }
"case"		{ return new Symbol(sym.tk_case); }
":"			{ return new Symbol(sym.dospuntos); }
"break"		{ return new Symbol(sym.tk_break); }
";"			{ return new Symbol(sym.puntocoma); }
"default"	{ return new Symbol(sym.tk_default); }
"while"		{ return new Symbol(sym.tk_while); }
"do"		{ return new Symbol(sym.tk_do); }
"for"		{ return new Symbol(sym.tk_for); }
"<"			{ return new Symbol(sym.menorque); }
"+"			{ return new Symbol(sym.mas); }
"continue"	{ return new Symbol(sym.tk_continue); }
">"			{ return new Symbol(sym.mayorque); }
"<="		{ return new Symbol(sym.menorigual); }
">="		{ return new Symbol(sym.mayorigual); }
","			{ return new Symbol(sym.coma); }
"-"			{ return new Symbol(sym.menos); }
"*"			{ return new Symbol(sym.por); }
"/"			{ return new Symbol(sym.diagonal); }
"class"		{ return new Symbol(sym.tk_class); }
"."			{ return new Symbol(sym.punto); }
"public"	{ return new Symbol(sym.tk_public); }
"private"	{ return new Symbol(sym.tk_private); }
"protected"	{ return new Symbol(sym.tk_protected); }
"void"		{ return new Symbol(sym.tk_void); }
"new"		{ return new Symbol(sym.tk_new); }
"||"		{ return new Symbol(sym.tk_or); }
"&&"		{ return new Symbol(sym.tk_and); }
"=="		{ return new Symbol(sym.igualigual); }
"!="		{ return new Symbol(sym.esdistinto); }
"%"			{ return new Symbol(sym.mod); }
"!"			{ return new Symbol(sym.diferente); }
"null"		{ return new Symbol(sym.tk_null); }
"char"		{ return new Symbol(sym.tk_char); }
"bool"		{ return new Symbol(sym.tk_bool); }
"true"		{ return new Symbol(sym.tk_true); }
"false"		{ return new Symbol(sym.tk_false); }
"return"	{ return new Symbol(sym.tk_return); }
"this"		{ return new Symbol(sym.tk_this); }
"++"		{ return new Symbol	(sym.masmas); }
"--"		{ return new Symbol(sym.menosmenos); }

<YYINITIAL> \"{STRING_TEXT}\" 
				{
				
				return new Symbol(sym.tk_cadena, yytext().Substring(1, yytext().Length - 2));
				}	
<YYINITIAL> {DIG}+ 
				{
				
				return (new Symbol(sym.tk_numero, yytext()));	
				}
<YYINITIAL> {ID} {
				
				return (new Symbol(sym.tk_identificador, yytext()));	
				}	
<YYINITIAL> \'{LETRAS}\' {
				
				return new Symbol(sym.tk_vchar, yytext().Substring(1, yytext().Length - 2));
				}	

[ \t\r\n\f] { /* ignore white space. */break; }
. { System.Console.Error.WriteLine("Illegal character: "+yytext());break; }
